package com.stt.videoprocess.design.controller;

import com.stt.videoprocess.design.model.VideoTask;
import com.stt.videoprocess.design.service.DesignVideoProcessingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 视频处理控制器
 * 1. 接收视频文件上传
 * 2. 创建处理任务
 * 3. 提供任务状态查询接口
 */
@RestController
@RequestMapping("/api/videos/v2")
public class SignVideoController {
    private static final Logger logger = LoggerFactory.getLogger(SignVideoController.class);
    private final DesignVideoProcessingService processingService;

    public SignVideoController(DesignVideoProcessingService processingService) {
        this.processingService = processingService;
    }

    @PostMapping("/upload")
    public ResponseEntity<String> handleFileUpload(@RequestParam("file") MultipartFile file) {
        logger.info("接收文件: {}", file.getOriginalFilename());
        String taskId = processingService.createProcessingTask(file);
        return ResponseEntity.ok(taskId);
    }

    @GetMapping("/status/{taskId}")
    public ResponseEntity<VideoTask> getTaskStatus(@PathVariable String taskId) {
        VideoTask task = processingService.getTaskStatus(taskId);
        return ResponseEntity.ok(task);
    }
}